<?php
	/**
	 * Created by PhpStorm.
	 * User: 陈森
	 * Date: 2020/12/30
	 * Time: 0:30
	 */

	namespace app\api\controller;


	use app\admin\model\member\BillModel;
	use core\basic\Controller;

	class BillController extends Controller
	{
		protected $model;

		public function __construct()
		{

			$this->model = new BillModel();

		}

		/**
		 *  $type '类型  1购买  2出售 3 充值  4转让 5使用 6接收 7提现',
		 * $genre  '1充值积分 2静态 3 动态 4激活码 5 排单积分',
		 *  * 前台用户提交 购买 统一购买  后台统一充值
		 */
		public function Bill()
		{
			$user_id = $this->Memcache(2, session('uid'))->id;
			$type = request('type', 'is_null', true, '流水类型');
			$genre = request('genre', 'num', true, '资金类型');
			$where['user_id'] = $user_id;
			$where['genre'] = $genre;
			if (!!$res = $this->model->GetBill($where, $type, 'details,add_time')) {
				json(1, $res);
			}
		}

		public function UserLog()
		{
			$Memcache = $this->Memcache(2, session('uid'));
//			$UserLog = $this->model->GetBill(['user_id'=>$Memcache->id]);
//			foreach ($UserLog as $k=>$value){
//				if($value->genre==1){
//					$data['Pay'][$k]=$value[]
//				}
//			}
//			json(1,$UserLog);
			//调取充值积分记录
			$UserLogPay = model('admin.member.Buy')->GetBuy(['user_id' => $Memcache->id]);    //调取充值积分记录
			$UserLogActovAtion = model('admin.member.Activation')->checkCode(['usermobile' => $Memcache->usermobile, 'status' => 1]);    //调取激活码记录
			$user_pool = model('admin.scheduling.Scheduling')->UserPoolInof(['user_id' => $Memcache->id]);    //排单池抢购额度

//			$arr = array();
//			$arrs = array();
//			foreach ($UserLogActovAtion as $k => $value) {
//				if ($value->source != '后台派送') {
//					$arr[$value->source]['count']=model('admin.member.Activation')->GetCount(['source'=>$value->source]);
//				}else{
//					$arrs[$value->source]['count'] = count($value);
//				}
//
//			}
//			json(1, $arr);
			$data = array(
				'UserLogPay' => $UserLogPay,
				'UserLogAtion' => $UserLogActovAtion,
				'user_pool' => $user_pool,
			);
			json(1, $data);
		}
	}